function DateUtil () {
  // eslint-disable-next-line no-extend-native
  Date.prototype.Format = function (fmt) { // author: meizz
    var o = {
      'M+': this.getMonth() + 1, // 月份
      'd+': this.getDate(), // 日
      'h+': this.getHours(), // 小时
      'm+': this.getMinutes(), // 分
      's+': this.getSeconds(), // 秒
      'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
      'S': this.getMilliseconds() // 毫秒
    }
    if (/(y+)/.test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
    }
    for (var k in o) {
      if (new RegExp('(' + k + ')').test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
      }
    }
    return fmt
  }
  /**
   * 获取当前年
   * @returns {number}
   */
  this.getCurrentYear = function () {
    return (new Date()).getFullYear()
  }
  /**
   * 获取当前月
   * @returns {number}
   */
  this.getCurrentMonth = function () {
    let month = (new Date()).getMonth() + 1
    return month < 10 ? '0' + month : month
  }
  /**
   * 获取当前日
   * @returns {number}
   */
  this.getCurrentDay = function () {
    let date = (new Date()).getDate()
    return date < 10 ? '0' + date : date
  }
  /**
   * 日期格式转换
   * @param fmt
   * @param date
   * @returns {*}
   */
  this.dateFormat = function (date, fmt) {
    if (!date) {
      return
    }
    if (!fmt) {
      fmt = 'yyyy-MM-dd hh:mm:ss'
    }
    return date.Format(fmt)
  }
  /**
   * 获取当前时间戳
   */
  this.getTimestamp = function () {
    return (new Date()).getTime()
  }
  /**
   * 获取当前日期
   * @returns {number}
   */
  this.getCurrentDateTime = function () {
    let date = new Date()
    let year = date.getFullYear()
    let month = date.getMonth()
    month = month < 10 ? '0' + month : month
    let day = date.getDate()
    day = day < 10 ? '0' + day : day
    let hour = date.getHours()
    hour = hour < 10 ? '0' + hour : hour
    let minute = date.getMinutes()
    minute = minute < 10 ? '0' + minute : minute
    let second = date.getSeconds()
    second = second < 10 ? '0' + second : second
    return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
  }
}

export default new DateUtil()
